package cn.dengl.sky.springboot.sys.service;

import cn.dengl.sky.springboot.common.base.dao.GenericDao;
import cn.dengl.sky.springboot.common.base.service.GenericService;
import cn.dengl.sky.springboot.sys.IService.IUserService;
import cn.dengl.sky.springboot.sys.dao.UserDao;
import cn.dengl.sky.springboot.sys.entity.QueryUser;
import cn.dengl.sky.springboot.sys.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userService")
@Transactional(rollbackFor = {IllegalArgumentException.class})
public class UserService extends GenericService<User,QueryUser> implements IUserService {
    @Resource
    private UserDao userDao;

    @Override
    protected GenericDao<User, QueryUser> getDao() {
        return userDao;
    }
    @Override
    public Map<String, Object> addUser(User user) {
       int index=userDao.save(user);
        System.out.println(index);
        Map<String, Object> map=new HashMap<String,Object>();
        if(index<0){
            map.put("status",-1);
            map.put("msg","添加失败");
        }else{
            map.put("status",1);
            map.put("msg","添加成功");
        }
        return map;
    }

    @Override
    public Map<String, Object> updateUser(User user) {
        return null;
    }

    @Override
    public List<User> loadAll() {
        QueryUser user=new QueryUser ();
        return userDao.query(user);
    }


}
